package view.teacher;

import java.awt.EventQueue;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.JInternalFrame;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.ImageIcon;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import base.NumberGeneration;
import controller.DateChooser;
import dao.ClassinformationDao;
import dao.MajorDao;
import dao.ManagerDao;
import dao.StudentDao;
import model.Classinformation;
import model.Major;
import model.Manager;
import model.Student;
import util.StringUtil;

import javax.swing.JPanel;
import javax.swing.border.TitledBorder;
import javax.swing.JRadioButton;
import javax.swing.JComboBox;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.ButtonGroup;

public class SeeStudentInfoInterfrm extends JInternalFrame {
	private JTextField textFieldName;
	private JTable tableStudent;

	private String sex = "男";
	private String mid = null;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					SeeStudentInfoInterfrm frame = new SeeStudentInfoInterfrm();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public SeeStudentInfoInterfrm() {
		setClosable(true);
		setIconifiable(true);
		setTitle("查看学生信息");
		setBounds(100, 100, 1201, 595);

		JLabel lblNewLabel = new JLabel("学生姓名：");

		textFieldName = new JTextField();
		textFieldName.setColumns(10);

		JButton btnNewButton = new JButton("查询");
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ArrayList<Student> arrayList = new ArrayList<Student>();
				ArrayList<Student> List = new ArrayList<Student>();
				arrayList = StudentDao.select();
				for (Student student : arrayList) {
					if (student.getStu_name().contains(textFieldName.getText())) {
						List.add(student);
					}
				}
				filltable(List);
			}
		});
		btnNewButton.setIcon(new ImageIcon(SeeStudentInfoInterfrm.class.getResource("/images/select.png")));

		JScrollPane scrollPane = new JScrollPane();
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(58)
					.addComponent(lblNewLabel)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(textFieldName, GroupLayout.PREFERRED_SIZE, 152, GroupLayout.PREFERRED_SIZE)
					.addGap(18)
					.addComponent(btnNewButton)
					.addContainerGap(18, GroupLayout.PREFERRED_SIZE))
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(21)
					.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 1146, Short.MAX_VALUE)
					.addGap(18))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(18)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(lblNewLabel)
						.addComponent(textFieldName, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
						.addComponent(btnNewButton))
					.addGap(18)
					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 477, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(173, Short.MAX_VALUE))
		);

		tableStudent = new JTable();
		tableStudent.setModel(new DefaultTableModel(
				new Object[][] { { null, null, null, null, null, null, null, null, null, null, null, null, null }, },
				new String[] { "\u5B66\u53F7", "\u59D3\u540D", "\u6027\u522B", "\u51FA\u751F\u65E5\u671F",
						"\u8EAB\u4EFD\u8BC1\u53F7", "\u7535\u8BDD", "\u7C4D\u8D2F", "\u90AE\u7BB1", "\u6C11\u65CF",
						"\u653F\u6CBB\u9762\u8C8C", "\u6240\u5728\u7CFB", "\u5165\u5B66\u5E74\u4EFD",
						"\u6240\u5728\u73ED\u7EA7" }) {
			boolean[] columnEditables = new boolean[] { false, false, false, false, false, false, false, false, false,
					false, false, false, false };

			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		tableStudent.getColumnModel().getColumn(2).setPreferredWidth(34);
		tableStudent.getColumnModel().getColumn(4).setPreferredWidth(100);
		tableStudent.getColumnModel().getColumn(6).setPreferredWidth(45);
		tableStudent.getColumnModel().getColumn(8).setPreferredWidth(45);
		scrollPane.setViewportView(tableStudent);
		getContentPane().setLayout(groupLayout);

		filltable(StudentDao.select());
	}

	private void filltable(ArrayList<Student> arrayList) {
		Major major;
		DefaultTableModel dtm = (DefaultTableModel) tableStudent.getModel();
		dtm.setRowCount(0);
		for (Student student : arrayList) {
			Vector v = new Vector();
			v.add(student.getStu_id());
			v.add(student.getStu_name());
			v.add(student.getStu_sex());
			v.add(student.getStu_birthday());
			v.add(student.getStu_sfz());
			v.add(student.getStu_tel());
			v.add(student.getStu_province());
			v.add(student.getStu_email());
			v.add(student.getNation());
			v.add(student.getPolitical());
			major = MajorDao.select(student.getM_id());
			v.add(major.getM_name());
			v.add(student.getEnrollmentYear());
			v.add(student.getCla_id());
			dtm.addRow(v);
		}
	}

	String[] politicalArr = { "", "中共党员", "中共预备党员", "共青团员", "民革党员", "民盟盟员", "民建会员", "民进会员", "农工党党员", "致公党党员", "九三学社社员",
			"台盟盟员", "无党派人士", "群众" };
	private final ButtonGroup buttonGroup = new ButtonGroup();




}
